
#include "MainUi.h"
#include "PipeLine.h"
#include "SensorMonitor.h"
#include "SpeedMonitor.h"
#include "Snap.h"
#include "SnapCaculator.h"
#include "SnapGenerator.h"
#include "History.h"
#include "Setting.h"
#include "settingDlg.h"
#include "Warnning.h"
#include <qobject.h>
#include <qpushbutton.h>

PipeLine::PipeLine(int id) : m_id(id)
{



	m_setting = new Setting(NULL, tr("setting dialog"), true, WStyle_Customize | WStyle_NoBorder, m_id);
	m_setting->setFixedSize(240, 320);
	m_setting->loadFile();


	m_history = new History(NULL, tr("setting dialog"), true, WStyle_Customize | WStyle_NoBorder, m_id);
	m_history->setFixedSize(240, 320);
	m_history->loadFile();


	m_speedMonitor = new  SpeedMonitor(m_setting);
	connect(m_speedMonitor, SIGNAL(speedSignal(const QString&)), this, SIGNAL(stateChange(const QString&)));



	m_fSnap = new Snap(m_speedMonitor, true);
	m_bSnap = new Snap(m_speedMonitor, false);
	m_snapCaculator = new SnapCaculator(m_fSnap, m_bSnap, m_setting);
	m_snapGenerator = new SnapGenerator(m_speedMonitor, m_setting);

	connect(m_snapGenerator, SIGNAL(snapCaculSignal()), m_snapCaculator, SLOT(caculateCar()));

	connect(m_snapCaculator, SIGNAL(carHappenSignal(const QString&)), m_history, SLOT(carHappen(const QString&)));


	m_warnning = new Warnning(m_id);
	connect(m_snapCaculator, SIGNAL(carHappenSignal()), m_warnning, SLOT(toWarnning()));

	connect(m_snapCaculator, SIGNAL(carHappenSignal()), m_snapGenerator, SLOT(carHappen()));
	connect(m_warnning, SIGNAL(cancelWarnning()), m_snapGenerator, SLOT(cancelWarnning()));
	connect(m_warnning, SIGNAL(cancelWarnning()), m_fSnap, SLOT(reset()));
	connect(m_warnning, SIGNAL(cancelWarnning()), m_bSnap, SLOT(reset()));


}

PipeLine::~PipeLine()
{
	delete m_warnning;
	delete m_snapGenerator;
	delete m_snapCaculator;
	delete m_bSnap;
	delete m_fSnap;
	delete m_speedMonitor;
	delete m_setting;
}


void PipeLine::settingDlgShow()
{
	m_setting->show();
}

void PipeLine::historyDlgShow()
{
	m_history->show();
}




void PipeLine::registerNotify(SensorMonitor* sm)
{

	SensorNotify* sensorNotify[3];
	sensorNotify[0] = m_speedMonitor;
	sensorNotify[1] = m_fSnap;
	sensorNotify[2] = m_bSnap;

	sm->registerNotify(sensorNotify, 3, 3 * m_id); 


}

